/*
 * @lc app=leetcode.cn id=28 lang=typescript
 *
 * [28] 实现 strStr()
 */

// @lc code=start
function strStr(haystack: string, needle: string): number {
    let result = -1;
    for (let index = 0; index < haystack.length; index++) {
        const element = haystack[index];
        if (element === needle[0]) {
            let tag = true;
            // 头部相同则开始向后查找
            for (let nC = 1; nC < needle.length; nC++) {
                const n = needle[nC];
                if (haystack[index + nC] !== n) {
                    tag = false;
                    break;
                }
            }
            if (tag) {
                return index;
            }
        }
    }
    return result;
}
// @lc code=end
